package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.entity.Comment;
import com.century.sjt.util.Constant;
import java.util.List;

/**
 * Created by 炳基 on 2016/8/25.
 * 评论列表适配
 */
public class mCommentListAdapter extends BaseAdapter {

    private List<Comment> dataList;
    private LayoutInflater mInflater;
    private RequestQueue mQueue;
    private Context mContext;

    public mCommentListAdapter(Context context, RequestQueue mQueue, List<Comment> dataList){
        mInflater= LayoutInflater.from(context);
        this.mQueue=mQueue;
        this.dataList=dataList;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        Comment item=null;
        if(null!=dataList){
            item=dataList.get(position);
        }
        return item;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView = mInflater.inflate(R.layout.topic_comment_item,null);
            holder = new ViewHolder();
            holder.tvName = (TextView) convertView.findViewById(R.id.name);
            holder.mImg = (ImageView) convertView.findViewById(R.id.image);
            holder.tvTime =(TextView)convertView.findViewById(R.id.time);
            holder.tvCotext = (TextView) convertView.findViewById(R.id.text);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        holder.tvName.setText(dataList.get(position).getUser().getNickName());
        holder.tvTime.setText(dataList.get(position).getCreateDateTime());
        holder.tvCotext.setText(dataList.get(position).getContent());
        String imgId= dataList.get(position).getUser().getImage();
        String imgUrl= Constant.ImageHost_Small + imgId;
        Glide.with(mContext).load(imgUrl).into(holder.mImg);
        return convertView;
    }

    private static class ViewHolder {
        private ImageView mImg;
        private TextView tvName;
        private TextView tvTime;
        private TextView tvCotext;
    }
}
